<template>
    <div>
        <el-table :data="catelist" border style="width: 100%" row-key="id" :tree-props="{ chidren: 'children' }">
            <el-table-column prop="id" label="分类编号" width="180">
            </el-table-column>
            <el-table-column prop="catename" label="分类名称" width="180">
            </el-table-column>
            <el-table-column  label="图片" width="180">
                <template slot-scope="item">
                   <img  v-if="item.row.img" :src="item.row.img" class="imgUrl" alt="">
                </template>
            </el-table-column>
            <el-table-column prop="name" label="状态">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" plain size="small">{{ item.status == 1 ? '启用' : '禁用' }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="status" label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" circle @click="edit(item.row.id)"></el-button>
                        <el-button type="danger" icon="el-icon-delete" circle @click="del(item.row.id)"></el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
import { cateDelete } from '../../request/api'
export default {
    data() {
        return {

        }
    },
    methods: {
        ...mapActions({
            getCate: 'cate/getCateListAction'
        }),
        // 编辑事件
        edit(id){
            this.$emit('edit',id)
        },
        // 删除事件
        del(id) {
            this.$confirm('你确定要删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                cateDelete({
                    id
                }).then(res => {
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        this.getCate()
                    } else {
                        this.$message.error(res.msg)
                    }
                })
            }).catch(()=>{
                this.$message({
                    type:'info',
                    message:'取消删除'
                })
            })
        }
    },
    mounted() {
        this.getCate()
    },
    watch: {},
    computed: {
        ...mapGetters({
            catelist: 'cate/getCateList'
        })
    },
    filters: {},
    components: {}
}
</script>
<style scoped>
.imgUrl{
    width: 60px;
    height: 60px;
}
</style>